package hng.service.admin.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import hng.dto.BannerDTO;
import hng.interceptor.LoginInterceptor;
import hng.model.AddressDO;
import hng.model.BannerDO;
import hng.mapper.BannerMapper;
import hng.model.LoginUser;
import hng.service.admin.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 轮播图表 服务实现类
 * </p>
 *
 * @author 告白
 * @since 2024-06-27
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, BannerDO> implements BannerService {

    @Autowired
    private BannerMapper bannerMapper;
    /**
     * 添加轮播图
     * **/
    @Override
    public void add(BannerDTO bannerDTO) {
        BannerDO bannerDO = new BannerDO();
        BeanUtils.copyProperties(bannerDTO,bannerDO);
        bannerMapper.insert(bannerDO);
    }
    /**
     * 删除轮播图
     * **/
    public void del(Integer id) {
        int row = bannerMapper.delete(new LambdaQueryWrapper<BannerDO>()
                .eq(BannerDO::getId,id)
        );
    }
    /**
     * 修改轮播图
     * **/
    @Override
    public void update(BannerDTO bannerDTO) {
        BannerDO bannerDO = new BannerDO();
        BeanUtils.copyProperties(bannerDTO,bannerDO);
        int row =  bannerMapper.update(bannerDO,new LambdaQueryWrapper<BannerDO>()
                .eq(BannerDO::getId, bannerDTO.getId())
        );
    }
    /**
     * 查询所有轮播图
     * **/
    @Override
    public List<BannerDO> bannerList() {
        List<BannerDO> bannerDOList = bannerMapper.selectList(null);
        return bannerDOList;
    }


}
